package tree;

import java.awt.*;
import java.util.Scanner;

/**
 * Created by hps on 17-5-12.
 */
public class TreeApp {
    public static void main(String[] args) {
        int value;
        Tree theTree = new Tree();

        theTree.insert(50, 1.5);
        theTree.insert(25, 1.2);
        theTree.insert(75, 1.7);
        theTree.insert(12, 1.5);
        theTree.insert(37, 1.2);
        theTree.insert(43, 1.7);
        theTree.insert(30, 1.5);
        theTree.insert(33, 1.2);
        theTree.insert(87, 1.7);
        theTree.insert(93, 1.5);
        theTree.insert(97, 1.5);

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("Enter first letter of show, ");
            System.out.print("insert, find, delete, exit or traverse: ");
            int choice = scanner.next().charAt(0);
            switch (choice) {
                case 's':
                    theTree.displayTree();
                    break;
                case 'i':
                    System.out.print("Enter value to insert: ");
                    value = scanner.nextInt();
                    theTree.insert(value, value + 0.9);
                    break;
                case 'f':
                    System.out.print("Enter value to insert: ");
                    value = scanner.nextInt();
                    Node found = theTree.find(value);
                    if (found != null) {
                        System.out.print("Found: ");
                        found.displayNode();
                        System.out.println();
                    } else {
                        System.out.println("Couldn't found " + value);
                    }
                    break;
                case 'd':
                    System.out.print("Enter value to delete: ");
                    value = scanner.nextInt();
                    boolean didDelete = theTree.delete(value);
                    if (didDelete)
                        System.out.println("Deleted " + value);
                    else
                        System.out.println("Couldn't delete " + value);
                    break;
                case 't':
                    System.out.print("Enter type 1, 2, 3: ");
                    value = scanner.nextInt();
                    theTree.traverse(value);
                    break;
                case 'e':
                    return;
                    default:
                        System.out.println("Invalid entry");
            }
        }
    }
}
